/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-08-13
 * Time: 22:42
 */
// https://leetcode.cn/problems/word-pattern/

    // 暴力求法
    // 1、将s中的字符串按单词分割，如果长度不等于pattern，返回false
    // 2、嵌套循环，如果pattern中第i位与第j位相等，s中i下标与j下标单词不一样，返回false
    // 3、如果pattern中第i位与第j位不相等，s中i下标与j下标单词一样，返回false
    // 4、返回true
public class Solution4 {
    public boolean wordPattern(String pattern, String s) {
        String[] strings = s.split(" ");
        if(pattern.length() != strings.length) {
            return false;
        }
        for (int i = 0; i < pattern.length()-1; i++) {
            for (int j = i+1; j < pattern.length(); j++) {
                if (pattern.charAt(i) == pattern.charAt(j)) {
                    if (!strings[i].equals(strings[j])) {
                        return false;
                    }
                } else {
                    if (strings[i].equals(strings[j])) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
